using NetBeans for rotate a figure in a label [migrated]

Posted by user134812 on Programmers See other posts from Programmers or by user134812
Published on 2014-06-06T14:34:39Z Indexed on 2014/06/06 15:40 UTC
Read the original article Hit count: 200

Filed under:
|

I was reading this post:

http://forums.netbeans.org/post-8864.html

and what I have done so far is to make a jFrame in NetBeans, on it I have drawn a jPanel and inisde the panel I have drawn a jLabel on it and use the icon property to put an image on it; until now all is so far so good.

I would like to make a program that everytime I click on the figure it rotates it to the right. Actually I have found the following code:

public class RotateImage extends JPanel{

// Declare an Image object for us to use.
Image image;

// Create a constructor method
public RotateImage(){
   super();
   // Load an image to play with.
   image = Toolkit.getDefaultToolkit().getImage("Duke_Blocks.gif");
}

public void paintComponent(Graphics g){
     Graphics2D g2d=(Graphics2D)g; // Create a Java2D version of g.
     g2d.translate(170, 0); // Translate the center of our coordinates.
     g2d.rotate(1);  // Rotate the image by 1 radian.
     g2d.drawImage(image, 0, 0, 200, 200, this);
}

but for what I see this code is for making the panel and other components from scratch, for my purposes it is not so good because I need to put several figures on my jFrame.

Could somebody can give me a hint how to do this?

© Programmers or respective owner

Related posts about java

Related posts about netbeans